package com.ruoyi.edh.dao;

import com.ruoyi.edh.domain.EdhGoodsDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

/**
 * @version :
 * @program: easyBuy
 * @description:
 * @author: 周爱鸿
 * @create: 2020-11-12 14:39
 **/
@Component
public class GoodsDetailDao {
	@Autowired
	private MongoTemplate mongoTemplate;

	/*
	 *@Author: 周爱鸿
	 *@Description:增
	 *@CreateDate: 2020/11/12 14:41
	 */
	public void save(EdhGoodsDetail detail){
		mongoTemplate.save(detail);
	}
	/*
	 *@Author: 周爱鸿
	 *@Description:改
	 *@CreateDate: 2020/11/12 14:41
	 */
	public void update(EdhGoodsDetail detail){
		Query query = new Query(Criteria.where("id").is(detail.getId()));
		Update update = new Update();
		update.set("details",detail.getDetails());
		mongoTemplate.updateFirst(query,update,EdhGoodsDetail.class);
	}
	/*
	 *@Author: 周爱鸿
	 *@Description:删除
	 *@CreateDate: 2020/11/12 14:41
	 */
	public void delete(Long id){
		mongoTemplate.remove(id);
	}
	/*
	 *@Author: 周爱鸿
	 *@Description:删除
	 *@CreateDate: 2020/11/12 14:41
	 */
	public EdhGoodsDetail find(Long id){
		Query query = new Query(Criteria.where("id").is(id));
		return mongoTemplate.findOne(query, EdhGoodsDetail.class);
	}
}
